﻿Imports AugmentLib.Database
Imports System.Configuration.ConfigurationManager
Imports AugmentLib.WebComponent
Imports AugmentLib.InputOutput.Encryption

Partial Class RenReportSearch
    Inherits System.Web.UI.Page

#Region " Properties "

    Public Property CurrentPage() As Integer
        Get
            'Looks for the current page in ViewState
            Dim objPage As Object = ViewState("_CurrentPage")
            If objPage Is Nothing Then
                Return 0
            Else
                'default to showing the first page
                Return CInt(objPage)
            End If
        End Get
        Set(ByVal value As Integer)
            ViewState("_CurrentPage") = value
        End Set
    End Property

    Public Property PageSize() As Integer
        Get
            'Looks for the current page in ViewState
            Dim objPageSize As Object = ViewState("_PageSize")
            If objPageSize Is Nothing Then
                Return 10
            Else
                'default to showing the first page
                Return CInt(objPageSize)
            End If
        End Get
        Set(ByVal value As Integer)
            ViewState("_PageSize") = value
        End Set
    End Property

#End Region

#Region " Paging and Page Size "

    Protected Sub lnkHead10Item_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkHead10Item.Click
        PageSize = 10
        LoadRenReportSearch()
    End Sub

    Protected Sub lnkHead25Item_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkHead25Item.Click
        PageSize = 25
        LoadRenReportSearch()
    End Sub

    Protected Sub lnkHead100Item_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkHead100Item.Click
        PageSize = 100
        LoadRenReportSearch()
    End Sub

    Protected Sub lnkHead150Item_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkHead150Item.Click
        PageSize = 150
        LoadRenReportSearch()
    End Sub

    Protected Sub lnkFoot10Item_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkFoot10Item.Click
        PageSize = 10
        LoadRenReportSearch()
    End Sub

    Protected Sub lnkFoot25Item_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkFoot25Item.Click
        PageSize = 25
        LoadRenReportSearch()
    End Sub

    Protected Sub lnkFoot100Item_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkFoot100Item.Click
        PageSize = 100
        LoadRenReportSearch()
    End Sub

    Protected Sub lnkFoot150Item_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkFoot150Item.Click
        PageSize = 150
        LoadRenReportSearch()
    End Sub

    Protected Sub btnMoveFirst_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnMoveFirst.Click
        CurrentPage = 0
        txtPageNo.Text = CurrentPage + 1
        LoadRenReportSearch()
    End Sub

    Protected Sub btnPrevious_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnPrevious.Click
        If CurrentPage > 0 Then
            CurrentPage = CurrentPage - 1
            txtPageNo.Text = CurrentPage + 1
            LoadRenReportSearch()
        End If
    End Sub

    Protected Sub btnGo_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnGo.Click
        If CInt(txtPageNo.Text < 1) Then
            txtPageNo.Text = 1
        End If

        If CInt(txtPageNo.Text > CInt(lblMaxPageCount.Text)) Then
            txtPageNo.Text = CInt(lblMaxPageCount.Text) + 1
        End If

        CurrentPage = CInt(txtPageNo.Text) - 1
        LoadRenReportSearch()

    End Sub

    Protected Sub btnNext_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnNext.Click
        If CurrentPage < CInt(lblMaxPageCount.Text) Then
            CurrentPage = CurrentPage + 1
            txtPageNo.Text = CurrentPage + 1
            LoadRenReportSearch()
        End If
    End Sub

    Protected Sub btnMoveLast_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnMoveLast.Click
        CurrentPage = CInt(lblMaxPageCount.Text)
        txtPageNo.Text = CurrentPage + 1
        LoadRenReportSearch()
    End Sub

#End Region

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Session.Item("StaffId") Is Nothing Then
            Response.Redirect("default.aspx")
        End If

        If Not Page.IsPostBack Then

            lblStaffUID.Text = Session.Item("StaffId").ToString
            lblStaffType.Text = Session.Item("StaffType").ToString

            If lblStaffType.Text = "2" Then
                'REN
                GetddlCountry()
                GetddlState(ddlCountry)
                GetddlContactName()
                GetrepPropertyType()
                trBoss.Visible = False
            Else
                GetddlListBy()
                GetddlCountry()
                GetddlState(ddlCountry)
                GetddlContactName()
                GetrepPropertyType()
                trBoss.Visible = True
            End If
        End If

        'Edited by minginn - To allow user to go back to the search page with same search selection
        '0-Back Page
        '1-Page Size
        '2-Current Page
        '3-Project
        '4-Road Name
        '5-Location Name
        '6-Country
        '7-State
        '8-Property Type
        '9-List Type
        '10-Price From
        '11-Price To
        '12-Contact Name
        '13-List By
        If Not Session("Back") Is Nothing Then
            Dim strBack As String = Session("Back").ToString
            Dim arr() As String = strBack.Split("ڡ")
            If arr(0).ToString.Contains("RenReportSearch.aspx") Then
                PageSize = CInt(arr(1).ToString)
                CurrentPage = CInt(arr(2).ToString)
                txtProject.Text = arr(3).ToString
                txtRoadName.Text = arr(4).ToString
                txtLocationName.Text = arr(5).ToString
                ddlCountry.SelectedValue = arr(6).ToString
                ddlState.SelectedValue = arr(7).ToString
                txtPropertyType.Text = arr(8).ToString
                ddlListType.SelectedValue = arr(9).ToString
                txtPriceFrom.Text = arr(10).ToString
                txtPriceTo.Text = arr(11).ToString
                ddlContactName.SelectedValue = arr(12).ToString
                ddlListBy.SelectedValue = arr(13).ToString
                Session.Remove("Back")
                LoadRenReportSearch()
            Else
                Session.Remove("Back")
            End If
         
        End If
    End Sub

    Private Sub GetddlCountry()
        Dim TempDT As New Data.DataTable
        Dim objDB As New Database(AppSettings("datasource"), AppSettings("database"), AppSettings("username"), AppSettings("password"), AppSettings("timeout"), AppSettings("pooling"))
        objDB.OpenConnection()

        objDB.dbVariable.SQLString = "SELECT CountryId,Country FROM AW_Country WHERE StatusDelete = 0 ORDER BY Country"
        objDB.FillData(TempDT, "Country", Database.SQLCommandType.NormalString)

        With ddlcountry
            .DataSource = TempDT
            .DataTextField = "Country"
            .DataValueField = "CountryId"
            .DataBind()
            .Items.Insert(0, "ANY")
            .Items(0).Value = ""
        End With

        objDB.CloseConnection()

    End Sub

    Private Sub GetddlState(ByVal ddlCountry As DropDownList)
        Dim strCountry As String
        Dim TempDT As New Data.DataTable
        Dim objDB As New Database(AppSettings("datasource"), AppSettings("database"), AppSettings("username"), AppSettings("password"), AppSettings("timeout"), AppSettings("pooling"))
        objDB.OpenConnection()

        If ddlCountry.SelectedValue = "" Then
            strCountry = Guid.Empty.ToString
        Else
            strCountry = ddlCountry.SelectedValue
        End If

        objDB.dbVariable.SQLString = "SELECT StateId,State FROM AW_State WHERE CountryId = @CountryId AND StatusDelete = 0 ORDER BY State"
        objDB.AddParameter("CountryId", Data.SqlDbType.UniqueIdentifier, New Guid(strCountry))
        objDB.FillData(TempDT, "State", Database.SQLCommandType.NormalString)

        With ddlState
            .DataSource = TempDT
            .DataTextField = "State"
            .DataValueField = "StateId"
            .DataBind()
            .Items.Insert(0, "ANY")
            .Items(0).Value = ""
        End With

        objDB.CloseConnection()

    End Sub

    Private Sub GetddlContactName()
        Dim TempDT As New Data.DataTable
        Dim strCreateBy As String = String.Empty
        Dim objDB As New Database(AppSettings("datasource"), AppSettings("database"), AppSettings("username"), AppSettings("password"), AppSettings("timeout"), AppSettings("pooling"))
        objDB.OpenConnection()

        If lblStaffType.Text = "2" Then
            'REN
            strCreateBy = "AND CreateBy=@CreateBy"
            objDB.AddParameter("CreateBy", Data.SqlDbType.UniqueIdentifier, New Guid(lblStaffUID.Text))
        Else
            If ddlListBy.SelectedValue <> "" Then
                strCreateBy = "AND CreateBy=@CreateBy"
                objDB.AddParameter("CreateBy", Data.SqlDbType.UniqueIdentifier, New Guid(ddlListBy.SelectedValue))
            End If
        End If

        objDB.dbVariable.SQLString = "SELECT Name, RenContactId FROM AW_RenContact WHERE StatusDelete=0 " & strCreateBy & " ORDER BY Name"
        objDB.FillData(TempDT, "RenContact", Database.SQLCommandType.NormalString)

        objDB.CloseConnection()

       
        With ddlContactName
            .DataSource = TempDT
            .DataTextField = "Name"
            .DataValueField = "RenContactId"
            .DataBind()
            .Items.Insert(0, "ANY")
            .Items(0).Value = ""
        End With

    End Sub

    Private Sub GetddlListBy()
        Dim TempDT As New Data.DataTable
        Dim objDB As New Database(AppSettings("datasource"), AppSettings("database"), AppSettings("username"), AppSettings("password"), AppSettings("timeout"), AppSettings("pooling"))
        objDB.OpenConnection()

        objDB.dbVariable.SQLString = "SELECT StaffId,Name FROM AW_Staff WHERE StatusDelete = 0 ORDER BY Name"
        objDB.FillData(TempDT, "AW_Staff", Database.SQLCommandType.NormalString)

        objDB.CloseConnection()

        With ddlListBy
            .DataSource = TempDT
            .DataTextField = "Name"
            .DataValueField = "StaffId"
            .DataBind()
            .Items.Insert(0, "ANY")
            .Items(0).Value = ""
        End With
    End Sub

    Protected Sub ddlListBy_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlListBy.SelectedIndexChanged
        GetddlContactName()
        ddlContactName.SelectedIndex = 0
    End Sub

    Private Sub GetrepPropertyType()
        Dim TempDT As New Data.DataTable
        Dim objDB As New Database(AppSettings("datasource"), AppSettings("database"), AppSettings("username"), AppSettings("password"), AppSettings("timeout"), AppSettings("pooling"))
        objDB.OpenConnection()

        objDB.dbVariable.SQLString = "SELECT TypeId,Type,CASE WHEN (LEN(TypeDesc)>=150) THEN SUBSTRING(TypeDesc, 1, 150) + '...' ELSE TypeDesc END AS TYPEDESC FROM AW_PropertyType WHERE StatusDelete = 0 AND Type like '%" & txtPropertyType.Text.Trim & "%' ORDER BY Type"
        objDB.FillData(TempDT, "AW_PropertyType", Database.SQLCommandType.NormalString)

        objDB.CloseConnection()

        repPropertyType.DataSource = TempDT
        repPropertyType.DataBind()
    End Sub

    Private Sub LoadPropertyType(Optional ByVal Type As String = "")

        Dim objDB As New Database(AppSettings("datasource"), AppSettings("database"), AppSettings("username"), AppSettings("password"), AppSettings("timeout"), AppSettings("pooling"))
        Dim TempDT As New Data.DataTable

        objDB.OpenConnection()
        If Type = "" Then
            objDB.dbVariable.SQLString = "SELECT TypeId,Type,CASE WHEN (LEN(TypeDesc)>=150) THEN SUBSTRING(TypeDesc, 1, 150) + '...' ELSE TypeDesc END AS TYPEDESC FROM AW_PropertyType ORDER BY Type"
        Else
            objDB.dbVariable.SQLString = "SELECT TypeId,Type,CASE WHEN (LEN(TypeDesc)>=150) THEN SUBSTRING(TypeDesc, 1, 150) + '...' ELSE TypeDesc END AS TYPEDESC FROM AW_PropertyType WHERE Type LIKE @Type ORDER BY Type"
            objDB.AddParameter("Type", Data.SqlDbType.NVarChar, "%" & Type & "%")
        End If
        objDB.FillData(TempDT, "PropertyType", Database.SQLCommandType.NormalString)
        objDB.CloseConnection()

        repPropertyType.DataSource = TempDT
        repPropertyType.DataBind()

    End Sub

    Protected Sub btnSearch_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSearch.Click
        LoadRenReportSearch()
    End Sub

    Protected Sub btnSearchPropertyType_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSearchPropertyType.Click
        If txtPropertyType.Text = "" Then
            LoadPropertyType()
        Else
            LoadPropertyType(txtPropertyType.Text)
        End If
        mpePropertyTypeEntry.Show()
    End Sub

    Protected Sub repPropertyType_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.RepeaterCommandEventArgs) Handles repPropertyType.ItemCommand

        If e.CommandName = "SelectType" Then
            'Edited by minginn - To allow user to go back to the search page with same search selection
            '0-Back Page
            '1-Page Size
            '2-Current Page
            '3-Project
            '4-Road Name
            '5-Location Name
            '6-Country
            '7-State
            '8-Property Type
            '9-List Type
            '10-Price From
            '11-Price To
            '12-Contact Name
            '13-List By
            Dim strBack As String
            strBack = "RenReportSearch.aspx" & "ڡ" & PageSize & "ڡ" & CurrentPage & "ڡ" & _
                    txtProject.Text.Trim & "ڡ" & txtRoadName.Text.Trim & "ڡ" & txtLocationName.Text.Trim & "ڡ" & _
                    ddlCountry.SelectedValue & "ڡ" & ddlState.SelectedValue & "ڡ" & txtPropertyType.Text.Trim & _
                    "ڡ" & ddlListType.SelectedValue & "ڡ" & txtPriceFrom.Text.Trim & _
                    "ڡ" & txtPriceTo.Text.Trim & "ڡ" & ddlContactName.SelectedValue & "ڡ" & ddlListBy.SelectedValue
            Session.Add("Back", strBack)

            Dim PropertyType As String = CType(repPropertyType.Items(e.CommandArgument).FindControl("lnkRepPropertyType"), LinkButton).Text
            txtPropertyType.Text = PropertyType
        End If
    End Sub

    Private Sub LoadRenReportSearch()
        Dim objDB As New Database(AppSettings("datasource"), AppSettings("database"), AppSettings("username"), AppSettings("password"), AppSettings("timeout"), AppSettings("pooling"))
        Dim TempDT As New Data.DataTable

        objDB.OpenConnection()

        Dim JoinProject, JoinRoad, JoinLocation, JoinPropertyType As String
        Dim strProject, strRoad, strLocation, strPropertyType As String
        Dim strCountry, strState, strListType, strContactName, strContactStatus, strListBy As String

        If txtProject.Text <> String.Empty Then
            JoinProject = " LEFT JOIN AW_Project AP ON RP.ProjectId = AP.ProjectId"
            strProject = " AND AP.Project LIKE @Project"
            objDB.AddParameter("Project", Data.SqlDbType.NVarChar, "%" & txtProject.Text.Trim.ToUpper & "%")
        Else
            JoinProject = String.Empty
            strProject = String.Empty
        End If

        If txtRoadName.Text <> String.Empty Then
            JoinRoad = " LEFT JOIN AW_Road AR ON RP.RoadId = AR.RoadId"
            strRoad = " AND AR.Road LIKE @Road"
            objDB.AddParameter("Road", Data.SqlDbType.NVarChar, "%" & txtRoadName.Text.Trim.ToUpper & "%")
        Else
            JoinRoad = String.Empty
            strRoad = String.Empty
        End If

        If txtLocationName.Text <> String.Empty Then
            JoinLocation = " LEFT JOIN AW_Location AL ON RP.LocationId = AL.LocationId"
            strLocation = " AND AL.Location LIKE @Location"
            objDB.AddParameter("Location", Data.SqlDbType.NVarChar, "%" & txtLocationName.Text.Trim.ToUpper & "%")
        Else
            JoinLocation = String.Empty
            strLocation = String.Empty
        End If

        If txtPropertyType.Text <> String.Empty Then
            JoinPropertyType = " LEFT JOIN AW_PropertyType AT ON RP.TypeId = AT.TypeId"
            strPropertyType = " AND AT.Type LIKE @PropertyType"
            objDB.AddParameter("PropertyType", Data.SqlDbType.NVarChar, "%" & txtPropertyType.Text.Trim.ToUpper & "%")
        Else
            JoinPropertyType = String.Empty
            strPropertyType = String.Empty
        End If

        If ddlCountry.SelectedValue <> "" Then
            strCountry = " AND RP.CountryId = @CountryId"
            objDB.AddParameter("CountryId", Data.SqlDbType.UniqueIdentifier, New Guid(ddlCountry.SelectedValue))
        Else
            strCountry = String.Empty
        End If

        If ddlState.SelectedValue <> "" Then
            strState = " AND RP.StateId = @StateId"
            objDB.AddParameter("StateId", Data.SqlDbType.UniqueIdentifier, New Guid(ddlState.SelectedValue))
        Else
            strState = String.Empty
        End If

        If ddlListType.SelectedValue <> "" Then
            strListType = " AND RP.ListType = @ListType"
            objDB.AddParameter("ListType", Data.SqlDbType.TinyInt, CInt(ddlListType.SelectedValue))
        Else
            strListType = String.Empty
        End If

        If ddlContactName.SelectedValue <> "" Then
            strContactName = " AND RC.RenContactId = @RenContactId"
            objDB.AddParameter("RenContactId", Data.SqlDbType.UniqueIdentifier, New Guid(ddlContactName.SelectedValue))
        Else
            strContactName = String.Empty
        End If

        If lblStaffType.Text = "2" Then
            strListBy = " AND RC.CreateBy = @CreateBy"
            objDB.AddParameter("CreateBy", Data.SqlDbType.UniqueIdentifier, New Guid(lblStaffUID.Text.Trim))
        Else
            If ddlListBy.SelectedValue <> "" Then
                strListBy = " AND RC.CreateBy = @CreateBy"
                objDB.AddParameter("CreateBy", Data.SqlDbType.UniqueIdentifier, New Guid(ddlListBy.SelectedValue))
            Else
                strListBy = String.Empty
            End If
        End If

        If ddlStatus.SelectedValue <> "" Then
            strContactStatus = " AND RC.Status = @Status"
            objDB.AddParameter("Status", Data.SqlDbType.TinyInt, CInt(ddlStatus.SelectedValue))
        Else
            strContactStatus = String.Empty
        End If

        objDB.dbVariable.SQLString = "SELECT RC.RenContactId, RC.Name, RC.Mobile, RC.Company, RC.Status FROM AW_RenContact RC LEFT JOIN  " & _
                                    "AW_RenProperty RP ON RC.RenContactId = RP.RenContactId" & JoinProject & JoinRoad & JoinLocation & JoinPropertyType & _
                                    " WHERE RC.StatusDelete=0" & strProject & strRoad & strLocation & strPropertyType & strCountry & _
                                    strState & strListType & strContactName & strListBy & strContactStatus & _
                                    " AND ((PriceFrom>=@PriceFrom AND PriceTo<=@PriceTo) OR (PriceFrom IS NULL OR PRICETO IS NULL))" & lblhidSortType.Text
        objDB.AddParameter("PriceFrom", Data.SqlDbType.Decimal, CDbl(txtPriceFrom.Text.Trim))
        objDB.AddParameter("PriceTo", Data.SqlDbType.Decimal, CDbl(txtPriceTo.Text.Trim))
        objDB.FillData(TempDT, "RenReportSearch", Database.SQLCommandType.NormalString)

        objDB.CloseConnection()

        'Creating a Paged Datasouce
        Dim objPaged As New PagedDataSource
        objPaged.DataSource = TempDT.DefaultView
        objPaged.AllowPaging = True
        objPaged.PageSize = PageSize
        objPaged.CurrentPageIndex = CurrentPage

        lblHeadNoOfItem.Text = TempDT.Rows.Count
        lblFootNoOfItem.Text = TempDT.Rows.Count

        repRenReportSearch.DataSource = objPaged
        repRenReportSearch.DataBind()

        lblMaxPageCount.Text = objPaged.PageCount - 1
        lblTotalPage.Text = " of " & objPaged.PageCount
    End Sub

    Protected Sub repRenReportSearch_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.RepeaterCommandEventArgs) Handles repRenReportSearch.ItemCommand
        If e.CommandName = "ViewList" Then
            'RenContactId
            'Edited by minginn - To allow user to go back to the search page with same search selection
            '0-Back Page
            '1-Page Size
            '2-Current Page
            '3-Project
            '4-Road Name
            '5-Location Name
            '6-Country
            '7-State
            '8-Property Type
            '9-List Type
            '10-Price From
            '11-Price To
            '12-Contact Name
            '13-List By         
            Dim strBack As String
            strBack = "RenReportSearch.aspx" & "ڡ" & PageSize & "ڡ" & CurrentPage & "ڡ" & txtProject.Text.Trim & "ڡ" & _
                txtRoadName.Text.Trim & "ڡ" & txtLocationName.Text.Trim & "ڡ" & ddlCountry.SelectedValue & "ڡ" & _
                ddlState.SelectedValue & "ڡ" & txtPropertyType.Text.Trim & "ڡ" & ddlListType.SelectedValue & "ڡ" & _
                txtPriceFrom.Text.Trim & "ڡ" & txtPriceTo.Text & "ڡ" & ddlContactName.SelectedValue & "ڡ" & ddlListBy.SelectedValue
            Session.Add("Back", strBack)
            Response.Redirect("RenReportView.aspx?id=" & SymmetricEncryptToHex(e.CommandArgument, "augment"))
        End If
    End Sub

    Private Function SortType(ByVal strSortType As String) As String
        Dim strSort As String
        If Right(strSortType, 1) = "▼" Then
            strSort = "ASC"
        Else
            strSort = "DESC"
        End If
        Return strSort
    End Function

    Protected Sub lnkName_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkName.Click
        If lnkName.Text = "Name▼" Then
            lnkName.Text = "Name▲"
        Else
            lnkName.Text = "Name▼"
        End If

        lblhidSortType.Text = "ORDER BY Name " & SortType(lnkName.Text) & _
                            ", Mobile " & SortType(lnkMobile.Text) & ", Company " & SortType(lnkCompany.Text) & _
                            ", Status " & SortType(lnkStatus.Text)
        btnSearch_Click(sender, e)
    End Sub

    Protected Sub lnkMobile_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkMobile.Click
        If lnkMobile.Text = "Mobile▼" Then
            lnkMobile.Text = "Mobile▲"
        Else
            lnkMobile.Text = "Mobile▼"
        End If

        lblhidSortType.Text = "ORDER BY Mobile " & SortType(lnkMobile.Text) & _
                            ", Name " & SortType(lnkName.Text) & ", Company " & SortType(lnkCompany.Text) & _
                            ", Status " & SortType(lnkStatus.Text)
        btnSearch_Click(sender, e)
    End Sub

    Protected Sub lnkCompany_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkCompany.Click
        If lnkCompany.Text = "Company▼" Then
            lnkCompany.Text = "Company▲"
        Else
            lnkCompany.Text = "Company▼"
        End If

        lblhidSortType.Text = "ORDER BY Company " & SortType(lnkCompany.Text) & _
                            ", Name " & SortType(lnkName.Text) & ", Mobile " & SortType(lnkMobile.Text) & _
                            ", Status " & SortType(lnkStatus.Text)
        btnSearch_Click(sender, e)
    End Sub

    Protected Sub lnkStatus_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkStatus.Click
        If lnkStatus.Text = "Status▼" Then
            lnkStatus.Text = "Status▲"
        Else
            lnkStatus.Text = "Status▼"
        End If

        lblhidSortType.Text = "ORDER BY Status " & SortType(lnkStatus.Text) & _
                            ", Name " & SortType(lnkName.Text) & ", Mobile " & SortType(lnkMobile.Text) & _
                            ", Company " & SortType(lnkCompany.Text)
        btnSearch_Click(sender, e)
    End Sub

    Protected Sub repRenReportSearch_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.RepeaterItemEventArgs) Handles repRenReportSearch.ItemDataBound
        If e.Item.ItemType = ListItemType.AlternatingItem Or e.Item.ItemType = ListItemType.Item Then

            Select Case CType(e.Item.FindControl("lblRepStatus"), LinkButton).Text
                Case "0"
                    CType(e.Item.FindControl("lblRepStatus"), LinkButton).Text = "ACTIVE"
                Case "1"
                    CType(e.Item.FindControl("lblRepStatus"), LinkButton).Text = "INACTIVE"
                Case "2"
                    CType(e.Item.FindControl("lblRepStatus"), LinkButton).Text = "ON-HOLD"
            End Select
        End If
    End Sub
End Class
